package my.mypool.core.thread;

import my.mypool.core.PoolablePool;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 2010-10-19
 * Time: 11:18:59
 * To change this template use File | Settings | File Templates.
 */
public class TaskWrapper implements Taskable {
    private Taskable task = null;
    private PoolablePool pool = null;
    private PoolableThread thread = null;

    public TaskWrapper(PoolablePool pool, PoolableThread thread, Taskable task) {
        this.pool = pool;
        this.thread = thread;
        this.task = task;
    }

    public void doTask() {
        try {
            task.doTask();
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (pool != null && thread != null) {
                try {
                    pool.returnObject(thread);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
